/*
 * @Author: song
 * @Description:底部滑动条
 * @Date: 2024年05月03日 星期五 22:05:43
 * @Modify:
 */

using SCore.Editor.WindowDraw;
using UnityEditor;
using UnityEngine;

namespace Function.SkillEditor.Editor
{
    public class SkillTimeLineHorScrollBar : NCommonView
    {
        private SkillTimeLineMarkerView _markerView;
        private ELineView _eLineView;

        private float _barLeftValue;
        private float _barRightValue;

        private float _scrollEnd; //进度条结束位置
        private bool _op = false;

        public void OnScrollBarGUI()
        {
            EditorGUI.BeginChangeCheck();
            var width = _markerView.GetRect().width - _markerView.GetZeroFrameWidth();
            var (showFrame, startFrame, endFrame) = _markerView.GetStartAndEndFrame();
            EditorGUILayout.MinMaxSlider(ref _barLeftValue, ref _barRightValue, 0, width);
            if (EditorGUI.EndChangeCheck())
            {
                _markerView._startFrame = Mathf.Max(0, (_barLeftValue * _scrollEnd) / width);
                _op = true;
                (showFrame, startFrame, endFrame) = _markerView.GetStartAndEndFrame();
                _scrollEnd = endFrame;
            }
            else
            {
                if (endFrame > _scrollEnd)
                {
                    _scrollEnd = endFrame;
                }

                _barLeftValue = (startFrame / _scrollEnd) * width;
                _barRightValue = (endFrame / _scrollEnd) * width;
            }
        }

        public void Bind(SkillTimeLineMarkerView markerView, ELineView lineView)
        {
            _markerView = markerView;
            _eLineView = lineView;
        }
    }
}